<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <link rel="shortcut icon" href="images/favicon.ico">
    <style>
        header a {
            text-decoration: none;
            color: #6c6c6c;
        }

        .el-table .el-table__cell {
            padding: 0; /*去掉自带的上下间距*/
        }

        .el-table .cell {
            white-space: nowrap; /*让内容在一行中显示*/
            text-overflow: ellipsis; /*让超出的内容以省略号来表示*/
        }

        .p_img:hover {
            position: relative;
            top: 5px; /*往下移动5个像素*/
            /*设置元素阴影:x偏移值 y偏移值 浓度 范围 颜色*/
            box-shadow: 0 0 10px 5px #333;
        }

        .el-main a {
            color: black;
            text-decoration: none;
        }

        .el-main a:hover {
            color: #666;
        }

    </style>
</head>
<body>
<div id="app">
    <el-container>
        <el-header height="150px">
            <div style="width: 1200px;margin: 0 auto">
                <img src="images/logo.png" style="width: 400px;height: 60px; vertical-align: middle" alt="">
                <a href="/">首页</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">热点资讯</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">商家入驻</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">社会招聘</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">校园招聘</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">帮助</a>
            </div>
            <!--导航菜单开始-->
            <div style="background-color: #82c8ec">

                <el-menu style="width: 1200px;margin: 0 auto"
                         :default-active="activeIndex" class="el-menu-demo"
                         background-color="#82c8ec"
                         text-color="#fff"
                         active-text-color="#fff"
                         mode="horizontal" @select="handleSelect">
                    <el-menu-item v-for="c in categoryArr" :index="c.id">{{c.name}}</el-menu-item>

                    <div style="float:right;position: relative;top: 10px">
                        <el-input v-model="wd" placeholder="请输入搜索内容">
                            <el-button @click="search()" slot="append" icon="el-icon-search"></el-button>
                        </el-input>
                    </div>
                </el-menu>
            </div>
            <!--导航菜单结束-->
        </el-header>
        <el-main style="width: 1200px;margin: 0 auto;">

            <!--商品列表开始-->
            <el-row gutter="20">
                <el-col span="6" v-for="p in productArr">
                    <el-card>
                        <a :href="'/detail.html?id='+p.id">
                            <img class="p_img" :src="p.url" width="100%" height="233" alt="">
                        </a>
                        <div>
                            <p style="font-size: 15px;height: 40px;margin-top: 0;display: -webkit-box;overflow: auto;webkit-line-clamp: 2;webkit-box-orient: vertical;">
                                <a :href="'/detail.html?id='+p.id">
                                    {{p.title}}
                                </a>
                            </p>
                            <p style="font-size: 12px;color: #666">
                                ￥{{p.price}} <s>{{p.oldPrice}}</s>
                                <span style="float: right">销量:{{p.saleCount}}</span>
                            </p>
                        </div>
                    </el-card>
                </el-col>
            </el-row>
            <!--商品列表结束-->
        </el-main>
        <el-footer>
            <div style="background-color: #0b0f3a;
            text-align: center;color: #b1b1b1;padding: 30px 0">
                <p>岁月静好，牵一片光阴于流年中，</p>
                <p>聆听花开的声音，携一缕馨香在生命的路口，芬芳过往。</p>
                <p>给时光一份浅浅的回眸，给心灵寻一份安暖，</p>
                <p>始终相信生命中的某些东西，深藏在心中，永远不会老去。</p>
            </div>
        </el-footer>
    </el-container>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                categoryArr: [],
                bannerArr: [],
                activeIndex: "1",
                topArr: [],
                productArr: [],
                wd: ""
            }
        },
        methods: {
            search() {
                axios.get("/product/selectByWd?wd="+v.wd).then(function(response){
                    v.productArr=response.data;
                })
            },
            handleSelect(key, keyPath) {
                console.log(key, keyPath);
                axios.get("/product/selectByCid?id="+key).then(function (response){
                    v.productArr=response.data;
                })
            }
        },
        created: function () {
            //发请求获取所有分类信息
            axios.get("/category/select").then(function (response) {
                v.categoryArr = response.data;
            })
            //判断地址栏中是否包含wd
            if (location.search.indexOf("wd")!=-1){//包含wd
                url="/product/selectByWd"+location.search;
            }else {
                url="/product/selectByCid"+location.search;
            }
            //发请求获取所有商品数据
            axios.get(url).then(function (response) {
                v.productArr = response.data;
            })
            if(location.search.indexOf("id")!=-1){
                let id=location.search.split("=")[1];
                this.activeIndex=id;
            }
        }
    })
</script>
</html>